<template>
    <el-header>
        <el-menu
        router
        :default-active="activeIndex2" 
        class="el-menu-demo" 
        mode="horizontal"
        background-color="#B3C0D1"
        text-color="#fff"
        active-text-color="#ffd04b">
        <el-menu-item index="/">学员管理系统</el-menu-item>
        <el-dropdown >
            <span class="el-dropdown-link">
                {{username}}
                <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>个人中心</el-dropdown-item>
                <el-dropdown-item @click.native='logOut'>注销</el-dropdown-item>
            </el-dropdown-menu>
            </el-dropdown>
        </el-menu>
    </el-header>
</template>
<script>
  export default {
    data() {
      return {
        activeIndex2: '1',
        username:localStorage.getItem('usr')
      };
    },
    // watch:{
    //     '$router'(){
    //         this.username = localStorage.getItem('usr');
    //     }
    // },
    methods: {
        logOut(){
          localStorage.clear();
          this.$router.push("/login")
        }
    }
  }
</script>
<style>
.el-dropdown{
    float: right;
    cursor: pointer;
}
</style>